package com.pro.service.imple;

import com.pro.mapper.JsMicrocircleMapper;
import com.pro.pojo.*;
import com.pro.service.JsMicrocircleService;
import com.pro.utils.RedisCatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 许振杰
 * @Date: 2022-01-07 10:24
 */
@Service
public class JsMicrocircleServiceImple implements JsMicrocircleService {

    @Autowired
    private JsMicrocircleMapper jsMicrocircleMapper;

    @Autowired
    private RedisCatch redisCatch;

    /**
    * @Title: 添加redis缓存
    * @author 许振杰
    * @date 2022/2/16 0016 9:28
    * @version V1.0
    */
    public List<JsActicleCategroy> ifRedisCacheHaveTree(String cacheName){
        List<JsActicleCategroy> acticleCategroy = redisCatch.getCacheList(cacheName);
        if(acticleCategroy==null || acticleCategroy.isEmpty()){
            acticleCategroy = jsMicrocircleMapper.getMicrocircleZtree();
            redisCatch.setCacheList(cacheName,acticleCategroy);
        }
        return acticleCategroy;
    }


    @Override
    public List<JsActicleCategroy> getMicrocircleZtree() {
        List<JsActicleCategroy> acticleCategroy = ifRedisCacheHaveTree("microcircleZtree");
        JsActicleCategroy categroy = new JsActicleCategroy();
        categroy.setActicleCategroyId(0);
        categroy.setArtcleCategroyName("请选择要查询的种类");
        categroy.setParentId(-1);
        //List<JsActicleCategroy> microcircleZtree = jsMicrocircleMapper.getMicrocircleZtree();
        acticleCategroy.add(categroy);
        return acticleCategroy;
    }

    @Override
    public boolean addZtreeNode(String artcleCategroyName, String createId, String createDate, Integer parentId) {
        redisCatch.deleteObject("microcircleZtree");
        return jsMicrocircleMapper.addZtreeNode(artcleCategroyName, createId, createDate, parentId);
    }

    @Override
    public boolean delZtreeNode(Integer acticleCategroyId) {
        redisCatch.deleteObject("microcircleZtree");
        return jsMicrocircleMapper.delZtreeNode(acticleCategroyId);
    }

    @Override
    public boolean editZtreeNode(Integer acticleCategroyId, String artcleCategroyName, String updateId, String updateDate) {
        redisCatch.deleteObject("microcircleZtree");
        return jsMicrocircleMapper.editZtreeNode(acticleCategroyId, artcleCategroyName, updateId, updateDate);
    }

    @Override
    public List<JsActicleCategroy> getMicrocircleZtreeById(Integer acticleCategroyId,Integer details) {
        return jsMicrocircleMapper.getMicrocircleZtreeById(acticleCategroyId,details);
    }

    @Override
    public List<JsMicrocircle> getMicrocircleTable(Integer details) {
        return jsMicrocircleMapper.getMicrocircleTable(details);
    }

    @Override
    public List<JsActicleCategroy> getMicrocircleSearch(Integer details,String artcleTitle , String userName,String account) {
        return jsMicrocircleMapper.getMicrocircleSearch(details,artcleTitle, userName, account);
    }

    @Override
    public JsMicrocircle getMicrocircleBymicrocircleId(Integer microcircleId) {
        return jsMicrocircleMapper.getMicrocircleBymicrocircleId(microcircleId);
    }

    @Override
    public boolean delMicrocircleBymicrocircleId(Integer microcircleId) {
        return jsMicrocircleMapper.delMicrocircleBymicrocircleId(microcircleId);
    }

    @Override
    public boolean delMicrocircleComment(Integer commodityId) {
        return jsMicrocircleMapper.delMicrocircleComment(commodityId);
    }

    @Override
    public boolean addMicrocircle(JsMicrocircle microcircle) {
        return jsMicrocircleMapper.addMicrocircle(microcircle);
    }

    @Override
    public boolean addCourseRecord(JsCourseRecord courseRecord) {
        return jsMicrocircleMapper.addCourseRecord(courseRecord);
    }

    @Override
    public boolean addMicrocircleLog(JsLog log) {
        return jsMicrocircleMapper.addMicrocircleLog(log);
    }

    @Override
    public List<JsComment> getMicrocircleComment(Integer commodityId,Integer type,Integer userType) {
        return jsMicrocircleMapper.getMicrocircleComment(commodityId, type, userType);
    }

    @Override
    public Integer getMicrocircleCommentNum(Integer commodityId,Integer type) {
        return jsMicrocircleMapper.getMicrocircleCommentNum(commodityId,type);
    }

    @Override
    public boolean addMicrocircleComment(JsComment comment) {
        return jsMicrocircleMapper.addMicrocircleComment(comment);
    }

    @Override
    public boolean editDisplay(JsComment comment) {
        return jsMicrocircleMapper.editDisplay(comment);
    }

    @Override
    public boolean deleteComment(Integer id) {
        return jsMicrocircleMapper.deleteComment(id);
    }

    /**
    * @Title: 根据id删除对应评论
    * @author Administrator
    * @date 2022/1/14 0014 9:41
    * @version V1.0
    */
    @Override
    public boolean delCommentByCommodityId(Integer commodityId, Integer type) {
        return jsMicrocircleMapper.delCommentByCommodityId(commodityId, type);
    }

    /**
    * @Title: 微圈草稿的修改
    * @author 许振杰
    * @date 2022/1/12 0012 16:00
    * @version V1.0
    */
    @Override
    public boolean editMicrocircle(JsMicrocircle microcircle) {
        return jsMicrocircleMapper.editMicrocircle(microcircle);
    }

    /**
    * @Title: 根据details状态获取微圈信息
    * @author 许振杰
    * @date 2022/1/12 0012 16:34
    * @version V1.0
    */
    @Override
    public List<JsMicrocircle> getMicrocircleBydetails(Integer details) {
        return jsMicrocircleMapper.getMicrocircleBydetails(details);
    }

    /**
    * @Title: 微圈状态信息的修改 details改为已提交
    * @author 许振杰
    * @date 2022/1/12 0012 21:23
    * @version V1.0
    */
    @Override
    public boolean editMicrocircleBymicrocircleId(Integer microcircleId, String releaseDate, Integer details) {
        return jsMicrocircleMapper.editMicrocircleBymicrocircleId(microcircleId, releaseDate, details);
    }

    /**
    * @Title: 微圈审核删除
    * @author 许振杰
    * @date 2022/1/13 0013 14:47
    * @version V1.0
    */
    @Override
    public boolean delCourseRecord(Integer courseId,Integer type) {
        return jsMicrocircleMapper.delCourseRecord(courseId,type);
    }

    /**
    * @Title: 个人微圈列表
    * @author 许振杰
    * @date 2022/1/13 0013 19:05
    * @version V1.0
    */
    @Override
    public List<JsMicrocircle> personalMicrocircle(Integer userId) {
        return jsMicrocircleMapper.personalMicrocircle(userId);
    }

    /**
    * @Title: 个人微圈的模糊查询
    * @author Administrator
    * @date 2022/1/13 0013 21:55
    * @version V1.0
    */
    @Override
    public List<JsMicrocircle> personalMicrocircleSearch(JsMicrocircle microcircle) {
        return jsMicrocircleMapper.personalMicrocircleSearch(microcircle);
    }

    /**
    * @Title: 微圈操作日志列表
    * @author 许振杰
    * @date 2022/1/14 0014 11:33
    * @version V1.0
    */
    @Override
    public List<JsLog> getMicrocirclLog(Integer logType) {
        return jsMicrocircleMapper.getMicrocirclLog(logType);
    }

    /**
    * @Title: 个人微圈模糊查询
    * @author 许振杰
    * @date 2022/1/14 0014 14:04
    * @version V1.0
    */
    @Override
    public List<JsLog> getMicrocirclLogSearch(JsLog log) {
        return jsMicrocircleMapper.getMicrocirclLogSearch(log);
    }

    /**
    * @Title: 个人微圈操作记录的删除
    * @author 许振杰
    * @date 2022/1/14 0014 15:28
    * @version V1.0
    */
    @Override
    public boolean delMicrocirclLog(Integer logId) {
        return jsMicrocircleMapper.delMicrocirclLog(logId);
    }
}
